package com.davidlife.javase.interfaces;

import java.awt.Toolkit;
import java.time.LocalTime;

import javax.swing.JOptionPane;
import javax.swing.Timer;

public class TimerAndToolkit {

	public static void main(String[] args) {
		Timer timer = new Timer(1000, e ->  {
			System.out.println("Bing... the time is" + LocalTime.now());
			Toolkit.getDefaultToolkit().beep();
		});
		timer.start();
		
		/*try {
			Thread.currentThread().join(5000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}*/
		
		//为了保持程序不退出，还可以这样用
		//keep program running until user selects "OK"
		JOptionPane.showMessageDialog(null, "Quit program ?");
		System.exit(0);
	}

}
